package com.yuwenchao.superafflatus;

import com.yuwenchao.superafflatus.pojo.entity.SuperBookfile;
import com.yuwenchao.superafflatus.service.SuperBookfileService;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.concurrent.TimeUnit;

@Slf4j
@SpringBootTest
public class LocalFuncrtion {

    @Autowired
     StringRedisTemplate stringRedisTemplate;

    @Autowired
    RedisTemplate redisTemplate;


    @Autowired
    RedisTemplate<Object,Object> myredisTemplate;


    @Autowired
    SuperBookfileService superBookfileService;


    @Autowired
    private BCryptPasswordEncoder encoding;


    @Test
    public void localFunction001(){

        stringRedisTemplate.opsForValue().append("k1","hello");
        String k1 = stringRedisTemplate.opsForValue().get("k1");
        System.out.println(k1);
        System.out.println("success!");

    }

    @Test
    public void localFunction002(){

        List<SuperBookfile> list = superBookfileService.list();
        myredisTemplate.opsForValue().set("v7",list,20, TimeUnit.HOURS);
        System.out.println("保存对象success!");
      //  JSONObject infoPageJson = new JSONObject(infoPageJsonObj);
    }



    @Test
    public void localFunction005(){

        //LocalDateTime格式的时间回显:2022-01-08T09:02:44

        LocalDateTime nowTime= LocalDateTime.now();
        System.out.println("当前时间:"+nowTime);
        System.out.println("当前时间转string:"+nowTime.toString());
        DateTimeFormatter dtf2 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

        String strDate2 = dtf2.format(nowTime);

        System.out.println(strDate2);


    }



    @Test
    public void localFunction003(){
        String encode = encoding.encode("admin123");
        System.out.println("Security密码加密："+encode);
        boolean matches = encoding.matches("123456",encode);
        System.out.println("验证密码是否正确！"+matches);
    }



}
